package com.lhb.aicodemother.ai.core.handler;


import com.lhb.aicodemother.ai.model.enums.CodeGenTypeEnum;
import com.lhb.aicodemother.model.entity.User;
import com.lhb.aicodemother.service.ChatHistoryService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import reactor.core.publisher.Flux;

/*
* 流处理器执行器
* */
@Slf4j
@Component
public class StreamHandlerExecutor {
    @Resource
    private JsonMessageStreamHandler jsonMessageStreamHandler;

    /*
    * 创建流处理器，并处理聊天历史记录
    * */
    public Flux<String> doExecute(Flux<String> originFlux,
                                  ChatHistoryService chatHistoryService,
                                  long appId, User loginUser, CodeGenTypeEnum codeGenTypeEnum) {
        return switch (codeGenTypeEnum){
            case VUE_PROJECT ->
                jsonMessageStreamHandler.handle(originFlux,chatHistoryService,appId,loginUser);

            case HTML,MULTI_FILE ->
                new SimpleTextStreamHandler().handle(originFlux,chatHistoryService,appId,loginUser);

        };
    }
}
